using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BaseData.DomainLib.AggregatesModel.SupplierAggregate;
using Microsoft.EntityFrameworkCore;
using Swimj.DomainLib.SeedWork;

namespace BaseData.InfrastructureLib.Repositories
{
    public class SupplierRepository : ISupplierRepository
    {
        private readonly BaseDataDbContext _baseDataDbContext;

        public IUnitOfWork UnitOfWork => _baseDataDbContext;

        public SupplierRepository(BaseDataDbContext baseDataDbContext)
        {
            this._baseDataDbContext = baseDataDbContext;
        }

        public Supplier Add(Supplier supplier)
        {
            return _baseDataDbContext.Suppliers.Add(supplier).Entity;
        }

        public async Task<Supplier?> Get(int id)
        {
            return await _baseDataDbContext.Suppliers.FirstOrDefaultAsync(supplier => supplier.Id == id);
        }
    }
}